import { http, ResponseType } from "/@/utils/http";

export interface IApi {
  getList(data: object): ResponseType;

  get(id: number): ResponseType;

  add(data: object): ResponseType;

  update(data: object): ResponseType;

  remove(id: number): ResponseType;
}

export default (url: string): IApi => {
  const getList = (data: object): ResponseType => {
    return http.request("get", url, { params: data });
  };

  const get = (id: number): ResponseType => {
    return http.request("get", `${url}/${id}`);
  };

  const add = (data: object): ResponseType => {
    return http.request("post", url, { data: data });
  };

  const update = (data: object): ResponseType => {
    return http.request("put", url, { data: data });
  };

  const remove = (id: number): ResponseType => {
    return http.request("delete", `${url}/${id}`);
  };

  return {
    getList,
    get,
    add,
    update,
    remove
  };
};
